<template>
  <Dialog :visible="addVisible" title="" :haderBox="0" :top="'5vh'" :width="1360" @close="addVisible = false">
    <div style="height: 750px;overflow-y: auto;padding: 5px;" v-if="addVisible">
       <el-tabs
          v-model="types" v-if="list.length > 0" 
          class="custom-tabs"
          >
          <el-tab-pane
              v-for="(tab,index) in list"
              :key="index"
              :label="tab.name"
              :name="tab.perms"
              >
          </el-tab-pane>
      </el-tabs> 
      <from1 :dataType="dataTypes" ref="reqFrom1Ref" v-if="types == 'jbxx' && dataTypes == 0" :storageId="storageIds" @closeDrawer="closeDrawer"></from1>
      <from2 :dataType="dataTypes" v-if="types == 'jbxx' && dataTypes == 1" :orderId="orderId" :storageId="storageIds" @closeDrawer="closeDrawer"></from2>
      <orderLog v-if="types == 'req-jl' && dataTypes == 1" :orderId="orderId" ></orderLog>
    </div>
    <template #footer v-if="types == 'jbxx' && dataTypes == 0">
      <el-button @click="closeDrawer">取消</el-button>
      <el-button type="primary" @click="from1RefOpen()">保存</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import from1 from './form1.vue'
import from2 from './form2.vue'
import orderLog from './orderLog.vue';
import stores from '@/store';

const addVisible = ref(false);
//'领用单', '变动流水'
const list = ref<any>([])
const orderId = ref<any>('')
const storageIds = ref<any>('')
const route = useRoute();
let menuList = ref<any>( await stores.useBaseDataStore().findMenuList(route.query.submenuId));
//console.log(menuList.value);

let menuItem = ref<any>(menuList.value.filter((item:any) => item.menuType == 2));
//console.log(menuItem.value);

const types = ref<string>('')
const reqFrom1Ref = ref<InstanceType<typeof from1>>();
const from1RefOpen = () => {
  //console.log('from1RefOpen');
  reqFrom1Ref.value?.open()
}
defineExpose<{
  open: (type:number,storageId:any) => void;
  open1: (menu: number,storageId:any) => void;
}>({
  open: (type:number,storageId:any) => {
    if(type == 0){
      list.value = [{
        name: '领用单',
        perms: 'jbxx'
      }]
    types.value  = 'jbxx'

      dataTypes.value = 0
    }
    storageIds.value  = storageId
    addVisible.value = true;
  },
  open1: (menu: number,storageId:any) => {
    list.value = [{
        name: '领用单',
        perms: 'jbxx'
    },
    {
      name: '变动流水',
      perms: 'req-jl'
    }]
    // menuItem.value.forEach((item:any) => {
    //     if(item.perms == 'req-jl'){
    //       item.name = item.menuName
    //       list.value.push(item)
    //     }
    // });
    types.value  = 'jbxx'

    
    orderId.value = menu
    dataTypes.value = 1
    storageIds.value = storageId
    addVisible.value = true;
  },
});


const dataTypes = ref<number>(0)
const parentMethod = (e: string) => {
  types.value = e
};

const emit = defineEmits(['closeDrawer']);
const closeDrawer = () => {
    addVisible.value = false;
    emit('closeDrawer');
};
</script>
<style lang="scss" scoped></style>
